package pl.edu.mimuw.irs.rcp.controller.editor.roles.command;

import org.eclipse.gef.commands.Command;

import pl.edu.mimuw.irs.core.model.design.resource.Role;

public class RenameRoleCommand extends Command {

	// *** Attributes

	private String newName;
	private String oldName;
	private Role role;
	public String getNewName() {
		return newName;
	}
	public String getOldName() {
		return oldName;
	}
	public Role getRole() {
		return role;
	}
	
	// *** Constructors

	public RenameRoleCommand(Role role, String newName) {
		this.role = role;
		this.newName = newName;
		this.oldName = role.getName();
	}

	// *** Methods
	
	@Override
	public void execute() {
		getRole().getRoles().remove(getOldName());
		getRole().setName(getNewName());
		getRole().getRoles().put(getNewName(), getRole());
		super.execute();
	}
	
	@Override
	public void undo() {
		getRole().getRoles().remove(getNewName());
		getRole().setName(getOldName());
		getRole().getRoles().put(getOldName(), getRole());
		super.undo();
	}
}
